package com.zyyh.utils;

import java.security.SecureRandom;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;

public class String2Utils {


    public static void main(String[] args) {
        String queryRandomString = queryRandomString(10);
        System.out.println(queryRandomString);

    }


    /**
     * 产生随机长度字符串
     * @param len
     * @return
     */
    public static String queryRandomString(int len){
        String source="1234567890abcdefghijklmnopqrstuvwxyz";
        SecureRandom random=new SecureRandom();
        StringBuilder builder=new StringBuilder();
        builder.append(new SimpleDateFormat("yyyyMMdd").format(new Date()));
        builder.append(UUID.randomUUID().toString().replace("-","").toLowerCase());
        for(int i=1;i<=len;i++){
            int nextInt = random.nextInt(source.length());
            char charAt = source.charAt(nextInt);
            builder.append(charAt);
        }
        return builder.toString();
    }
}
